package com.rt.java.util.concurrent;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;

public class AtomicIntegerDemo {

    static int num = 0;
    static AtomicInteger ai = new AtomicInteger(0);

    public static void main(String[] args) throws InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);
        CountDownLatch countDownLatch = new CountDownLatch(3);
        for (int i = 0; i < 3; i++) {
            threadPool.execute(() -> {
                for (int j = 0; j < 10000; j++) {
                    //num++;
                    ai.incrementAndGet();
                }
                countDownLatch.countDown();
            });
        }
        countDownLatch.await();
        //System.out.println(num);
        System.out.println(ai.get());
    }

}
